
	$(document).ready(function(){
		$('input#deadline	').datepicker({
			showOn: "button",
			changeMonth : true,
			dateFormat: 'yy-mm-dd',
			timeFormat: 'hh-mm-ss'
		});
	});
	$('input.add_button').click(function(){
		alert('yeah');
		if ($('#task_name').val().length == 0 ||
				$('#project_name').val().length == 0 ||
				$('#assign_user').val().length == 0 ||
				$('#task_priority').val().length == 0 ||
				$('#deadline').val().length == 0 ||
				$('#task_description').val().length == 0) {
			return false;
		}
		
		//change button to loadding
		$('input.add_button').attr('disabled',true);
		$('input.add_button').attr('value','Loading');
		var str = '/ajax/task/add_task/'+'<?php echo Request::current()->param('project_id','')?>';
		$.ajax({
			url: str,
			type: 'POST',
			data: ({'name': $("#task_name").val(),
					'assign_user':$("#assign_user").val(),
					'project_id':$("#project_name").val(), 
					'priority':$('#task_priority').val(),
					'deadline' : $('#deadline').val(),
					'description' : $('#task_description').val()
					}),
			success: function(ret) {
					var data = $.parseJSON(ret);
					if (data.success)
					{
						var element = new Object();
						element = {
								id: data.id,
								user_displayname: '<?php echo Helper_Auth::instance()->get_user_displayname()?>',
								project_id: <?php echo $project['id']?>,
								project_name: '<?php echo $project['name']?>',
								name: $("#task_name").val(),
								assign_user:$("#assign_user").val(),
								project_id:$("#project_name").val(), 
								priority:$('#task_priority').val(),
								deadline: $('#deadline').val(),
								description: $('#task_description').val(),
								assign_user_displayname: $('select#assign_user option:selected').text(),
								assign_task_status: <?php echo Helper_MyConst::TASK_ON_PROGRESS?>, 
						};
						add_new_task(element);
					}
			},
			error: function() {
				$('input.add_button').attr('disabled',false);
				alert('Error occured!');
			},
			complete: function() {
				$('input.add_button').attr('disabled', false);
				$('input.add_button').attr('value','Add');
				$("#task_name").attr('value','');
				$("#task_description").attr('value','');
				$("#deadline").attr('value','');
			}
		});
		return false;	
	});
